 import { defineStore } from "pinia";

 export const useGlobleStore = defineStore('globle',{
    //id:"globle",
    state : () => {
        return {
            username:'',
            type: 0, 
            
            messageNum:0,
            avater:'',
            isLogin:false,
        }
    },
    getters: {
        addMsg(){
            this.messageNum++
        },
        subMsg(){
            if(this.messageNum > 0)this.messageNum--;
        },
    },
    actions: {
        //store
        storeUsrname(username : string){
            this.username = username
        },
        storeUsrtype(type : number){
            this.type = type
        },
        setMsgNum(msg:number){
            this.messageNum = msg
        },
        getMsgNum(){
            return this.messageNum
        },
        setAvater(address:string){ this.avater = address},
        setLoginState(login:boolean){this.isLogin = login},
        //get
        getUsrname(){ return this.username },
        getUsrtype(){ return this.type },
        getAvater(){ return this.avater},
        getLoginState(){return this.isLogin},
        clearData(){
            this.username='',
            this.type = 0,
            this.isLogin = false
        }
    },
    persist:{
        enabled:true,
    }
 })